using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using System.Xml.Serialization;
using org.qsoft.rpcfx.core;
using org.qsoft.rpcfx.bean;
using nrpcfx.org.qsoft.rpcfx.bean.xml;
using nrpcfx.org.qsoft.rpcfx.bean.json;

namespace nrpcfx.test
{
    class Program
    {

        static void Main(string[] args)
        {


            testJson();

            //string url = "http://localhost:2693/rpcfxweb/";
            //string data = "<naf.core.interfaces.support.BaseServiceRequest><serviceName><string>naf.core.test.Itest</string></serviceName><methodName><string>doit</string></methodName><paramTypeNames><value><string>int</string></value></paramTypeNames><args><value><int>2</int></value></args></naf.core.interfaces.support.BaseServiceRequest>";
            ////string encode = System.Web.HttpUtility.UrlEncode(data);
            //string result = NetUtil.getXmlFromServer(url, "param", data);
            //Console.WriteLine(result);

            //using (ManagementClass mc = new ManagementClass("Win32_Processor"))
            //{
            //    Console.WriteLine("==== Win32_Processor ====\r\n");
            //    ManagementObjectCollection moc = mc.GetInstances();
            //    foreach (ManagementObject mo in moc)
            //    {
            //        Console.WriteLine(String.Format ("ProcessorId: {0}\r\n\r\n", mo["ProcessorId"]));
            //    }
            //}

            //-----------------------------------------


            //testSimple1();

            //Console.WriteLine(HttpUtility.HtmlEncode(" </xml>'\r\n'0x1a"));



            Console.ReadLine();
        }


        private static void testJson()
        {
            IServiceResponse response = new BaseServiceResponse();

            response.returnValue = (" setst !");
            QJsonWriter writer = new QJsonWriter();
            string json = writer.Serialize(response);
            Console.WriteLine(json);
            Console.WriteLine("------------------");

            MyBean mb = new MyBean();
            mb.id = 12;
            mb.name = "asdfasdf";
            mb.ids = new int[] { 1,2,4,6};

            json = writer.Serialize(mb);
            Console.WriteLine(json);
            Console.WriteLine("------------------");

        }

        private static void testSimple1()
        {
            IServiceResponse response = new BaseServiceResponse();

            response.returnValue = (" </xml>");
            //new int[] { 1, 2, 3 };

            QXmlWriter w = new QXmlWriter();

            string xml = w.Serialize(response);

            //Type I = typeof(IServiceResponse);
            //Type B = typeof(BaseServiceResponse);
            

            //Console.WriteLine(B.IsAssignableFrom(I));
            //Console.WriteLine(I.IsAssignableFrom(B));

            //Console.WriteLine(B.IsSubclassOf(I));

            Console.WriteLine(xml);
            Console.WriteLine("------------------");
        }

        private static void NewMethod()
        {
            Itest it = (Itest)ServiceFactory.getService(typeof(Itest));

            string s = it.doit(1);
            Console.WriteLine(s);


            MyBean mb = it.test();


            Console.WriteLine("------------------------------");

            Console.WriteLine(mb.name);

            Console.WriteLine("------------------------------");

            Console.WriteLine(it.GetType().FullName);

            Console.WriteLine(typeof(Itest).IsAssignableFrom(it.GetType()));

            //ObjCreator oc = new ObjCreator(s);
            //IServiceRequest obj = (IServiceRequest)oc.createObjTarget();
            //Console.WriteLine(obj.serviceName + "." + obj.methodName);
        }




    }


    public interface Itest
    {
        string doit(int i);
        //string doit(string s, int i);
        MyBean test();
    }

    public class MyBean
    {
        private int _id;

        public int id
        {
            get { return _id; }
            set { _id = value; }
        }


        private string _name;

        public string name
        {
            get { return _name; }
            set { _name = value; }
        }


        private int[] _ids;

        public int[] ids
        {
            get { return _ids; }
            set { _ids = value; }
        }


        private MyBean _mb;

        public MyBean mb
        {
            get { return _mb; }
            set { _mb = value; }
        }

    }
}
